package com.atguigu5.Blob;

import java.io.File;
import java.io.FileInputStream;
import java.sql.Connection;

import org.junit.Test;

import com.atguigu3.util.JDBCUtils;
import com.mysql.jdbc.PreparedStatement;

/**
 * 使用PreparedStatement操作Blob的数据
 * @author 石文学
 *
 */
public class BlobTest {
	//向数据表customers中插入Blob的数据
	@Test
	public void testInsert() throws Exception
	{
		Connection conn = JDBCUtils.getConnection();
		String sql = "insert into customers(name,email,birth,photo) values(?,?,?,?)";
		PreparedStatement ps = (PreparedStatement) conn.prepareStatement(sql);
		ps.setObject(1, "普元庆");
		ps.setObject(2, "pyq@126.com");
		ps.setObject(3, "2002-01-01");
		FileInputStream is = new FileInputStream(new File("微信图片_20220828222640.jpg"));
		ps.setObject(4, is);
		
		ps.execute();
		
		conn.close();
		ps.close();
	}
}
